<?php
/*
 * ************************************************* 
 * Created on :2012-3-20 7:58:03
 * Encoding   :UTF-8
 * Description:
 * 
 * @Author @lqs <soso2501@gmail.com>
 * @WAP_WEIBO (C)1996-2099 SINA Inc. 
 * ************************************************
 */

class LException extends Exception {

    protected $description;

    /**
     * Creates a new system_exception
     * 
     * @param	string		$message	error message
     * @param	integer		$code		error code
     * @param	string		$description	description of the error	
     */
    public function __construct($message = '', $description = '') {
        parent::__construct($message, 0);
        $this->description = $description;
    }

    /**
     * Returns the description of this exception.
     * 
     * @return 	string
     */
    public function getDescription() {
        return $this->description;
    }

    /**
     * Removes database password from stack trace.
     * @see Exception::getTraceAsString()
     */
    public function __getTraceAsString() {
        return $this->getTraceAsString();
    }

    /**
     * Prints this exception.
     * 
     */
    public function show() {
        if (defined('DEBUG') && DEBUG) {
            $this->errorSystem();
        } else {
            $this->errorFriendly();
        }
    }

    protected function errorSystem() {
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en">
            <head>
                <title>当您看到这个页面是，代表着网站出现了一个严重的错误:</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <style type="text/css">
                    .systemException { border: 1px outset lightgrey; padding: 3px; background-color: lightgrey; text-align: left; overflow: auto; font-family: Verdana, Helvetica, sans-serif; font-size: .8em; }
                    .systemException div { border: 1px inset lightgrey; padding: 4px; }
                    .systemException h1 { background-color: #154268; padding: 4px; color: #fff; margin: 0 0 3px 0; font-size: 1.15em; }
                    .systemException h2 { font-size: 1.1em; margin-bottom: 0; }
                    .systemException pre, .systemException p { margin: 0; }
                    .systemException pre { font-size: .85em; font-family: "Courier New"; }
                </style>
            </head>
            <body>
                <div class="systemException">
                    <h1>当您看到这个页面是，代表着网站出现了一个严重的错误:</h1>
                    <div>
                    <!-- <p><?php echo $this->getDescription(); ?></p> -->
                        <h2>详细错误错误信息如下:</h2>
                        <p><b>信息:</b> <?php echo htmlspecialchars($this->getMessage()); ?><br />			
                            <b>文件:</b> <?php echo htmlspecialchars($this->getFile()); ?> (<?php echo $this->getLine(); ?>)<br />
                            <b>PHP版本:</b> <?php echo htmlspecialchars(phpversion()); ?><br />
                            <b>时间:</b> <?php echo gmdate('r'); ?><br />
                            <b>请求页:</b> <?php if (isset($_SERVER ['REQUEST_URI'])) echo htmlspecialchars($_SERVER ['REQUEST_URI']); ?><br />
                            <b>来源页:</b> <?php if (isset($_SERVER ['HTTP_REFERER'])) echo htmlspecialchars($_SERVER ['HTTP_REFERER']); ?><br />
                        </p>
                        <h2>跟踪:</h2>
                        <pre><?php echo htmlspecialchars($this->__getTraceAsString()); ?></pre>
                    </div>
                </div>
            </body>
        </html>
        <?php
    }

    protected function errorFriendly() {
        echo '对不起，您浏览的网页出错了！';
    }

}

/* End of file local_exception */


